package hy.config;

import hy.entity.Dog;
import hy.entity.Person;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@ConditionalOnBean(name="user")//当存在user这个bean时才加载这个配置类到容器
//@ConditionalOnMissingBean(name="user1")//不存在时才加载
//@ConditionalOnClass(User.class)//当存在这种类型class对象才加载
@Configuration
public class MyCfg2 {
    @Bean
    @ConfigurationProperties("dog")
    Dog getD(){
        return new Dog();
    }
    @ConditionalOnBean(name="getD")//容器中存在getD这个bean就把getP这个bean注入到容器中
    @Bean
    Person getP(){
        Person p=new Person();
        p.setDog(getD());
        return p;
    }
}